package com.banmoon.flyweight;

import java.rmi.activation.UnknownObjectException;

public class Chessboard {

    public ChessPieces[][] chessboard = new ChessPieces[19][19];

    private ChessPiecesFactory chessPiecesFactory = new ChessPiecesFactory();

    public void put(int x, int y, String type) throws UnknownObjectException {
        if(x<0 || x>18 || y<0 || y>18)
            throw new UnsupportedOperationException("不能在此落子");
        if(!"white".equals(type) && !"black".equals(type))
            throw new UnknownObjectException("未知的棋子");
        chessboard[x][y] = chessPiecesFactory.getChessPieces(type);
    }

    public void showChessboard(){
        for (int i = 0; i < chessboard.length; i++) {
            for (ChessPieces chessPieces : chessboard[i]) {
                if(chessPieces!=null)
                    System.out.print(chessPieces.getColor());
                else
                    System.out.print("空");
            }
            System.out.println();
        }
    }

}
